package com.seaboxdata.utils;

import com.seaboxdata.threadHandler.GpsRecordHandler;
import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * @author
 * @create 2021-05-25 11:30
 **/
public class TestActiveMq {
    public static void main(String[] args) {
        ConnectionFactory factory;//连接实例

        Connection connection = null;//收发的线程实例

        Session session;//消息发送目标地址

        Destination destination;try{//实例化连接工厂

            factory = new ActiveMQConnectionFactory("RdMqUs01", "RgDtMq2021", "tcp://139.159.142.127:18090");//获取连接实例

            connection =factory.createConnection();//启动连接

            connection.start();//创建接收或发送的线程实例

            session =connection.createSession(Boolean.FALSE, Session.AUTO_ACKNOWLEDGE);//创建队列(返回一个消息目的地)

            destination = session.createQueue("Queue.GpsRecord");

            MessageConsumer consumer =session.createConsumer(destination);//消息发布者添加监听器

            consumer.setMessageListener(new GpsRecordHandler());

        }catch(JMSException e) {
            e.printStackTrace();
        }

    }
}
